import 'package:photo_frame/user/user_manager.dart';
import 'package:photo_frame/utils/a_logger.dart';
import 'package:photo_frame/utils/color_util.dart';

class MemberModel {
  num? id;
  String? frame_id;
  String? name;
  String? email;
  int? color;
  int? get type =>
      isActive == 1 ? (UserManager.instance.getId() == id ? 1 : 0) : 2;

  int? isActive = 0; //是否为真实账号

  bool selected = true; //本地地段

  int get fixedColor => 0xff000000 | (color ?? 0);

  MemberModel({this.id,this.frame_id, this.name, this.email, this.color, this.isActive});

  factory MemberModel.fromMap(Map<String, dynamic> map) {
    return MemberModel(
      id: map['id'] as num?,
      frame_id: map['frame_id'] as String?,
      name: map['name'] as String?,
      email: map['email'] as String?,
      color: (map['color'] as int?) ?? 0xffFF6F6F,
      isActive: (map['isActive'] as int?) ?? 0,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'frame_id': frame_id,
      'name': name,
      'email': email,
      'color': color,
      'isActive': isActive
    };
  }

  void updateWithModel(MemberModel model) {
    id = model.id ?? id;
    frame_id = model.frame_id ?? frame_id;
    name = model.name ?? name;
    email = model.email ?? email;
    color = model.color ?? color;
    isActive = model.isActive ?? isActive;
  }
}
